﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace BoAddonBiz_FreightForwarder.Cost.Bill_Draft
{
    internal class BillDraft
    {
        public BillDraft()
        {
            _Lines = new BillDraftLines();
            _Rate = -1;
        }

        private Bo.OrderType _OrderType;
        private bool _IsModify;
        private int _DraftKey;

        private string _CardCode;
        private string _CardName;
        private DateTime _DocDate;
        private string _Currency;
        private double _Rate;
        private BillDraftLines _Lines;

        public Bo.OrderType OrderType
        {
            get { return _OrderType; }
            set { _OrderType = value; }
        }

        public bool IsModify
        {
            get { return _IsModify; }
            set { _IsModify = value; }
        }
        public int DraftKey
        {
            get { return _DraftKey; }
            set { _DraftKey = value; }
        }

        public string CardCode
        {
            get { return _CardCode; }
            set { _CardCode = value; }
        }
        public string CardName
        {
            get { return _CardName; }
            set { _CardName = value; }
        }
        public DateTime DocDate
        {
            get { return _DocDate; }
            set { _DocDate = value; }
        }
        public string Currency
        {
            get { return _Currency; }
            set { _Currency = value; }
        }
        public double Rate
        {
            get { return _Rate; }
            set { _Rate = value; }
        }
        public BillDraftLines Lines
        {
            get { return _Lines; }
        }
    }
    internal class BillDrafts : List<BillDraft>
    {
        public BillDraft Add()
        {
            BillDraft oDraft = new BillDraft();
            this.Add(oDraft);
            return oDraft;
        }
        public BillDraft GetCardCode(string CardCode)
        {
            foreach (BillDraft oDraft in this)
            {
                if (oDraft.CardCode == CardCode)
                    return oDraft;
            }
            return this.Add();
        }
    }
    internal class BillDraftLine : INotifyPropertyChanging, INotifyPropertyChanged
    {
        private string _ItemCode;

        public string ItemCode
        {
            get { return _ItemCode; }
            set { _ItemCode = value; }
        }
        private double _Price;

        public double Price
        {
            get { return _Price; }
            set { _Price = value; }
        }
        private double _Quantity;

        public double Quantity
        {
            get { return _Quantity; }
            set
            {
                if (_Quantity != value)
                {
                    if (PropertyChanging != null)
                        PropertyChanging(this, new PropertyChangingEventArgs("Quantity"));
                    _Quantity = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Quantity"));
                }
            }
        }
        private int _BaseType;

        public int BaseType
        {
            get { return _BaseType; }
            set { _BaseType = value; }
        }
        private int _BaseEntry;

        public int BaseEntry
        {
            get { return _BaseEntry; }
            set { _BaseEntry = value; }
        }
        private int _BaseLine;

        public int BaseLine
        {
            get { return _BaseLine; }
            set { _BaseLine = value; }
        }

        private string _Currency;

        public string Currency
        {
            get { return _Currency; }
            set { _Currency = value; }
        }
        private double _Rate;
        public double Rate
        {
            get { return _Rate; }
            set { _Rate = value; }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;
    }
    internal class BillDraftLines : List<BillDraftLine>
    {
        public new BillDraftLine this[int index]
        {
            get { return this[index]; }
            set { this[index] = value; }
        }
        public BillDraftLine Add()
        {
            BillDraftLine line = new BillDraftLine();
            this.Add(line);
            return line;
        }
        public bool DeleteDraftLine(int BaseType, int BaseEntry, int BaseLine)
        {
            foreach (BillDraftLine line in this)
            {
                if (line.BaseType == BaseType && line.BaseEntry == BaseEntry && line.BaseLine == BaseLine)
                {
                    return this.Remove(line);
                }
            }
            return false;
        }
    }
}
